#!/bin/bash
#
# NDAS driver monitoring
#
# Copyright (C) 2008 Stefan Majewsky <majewsky@gmx.net>
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place, Suite 330, Boston, MA 02111-1307 USA
#
# /etc/init.d/ndas
#
### BEGIN INIT INFO
# Provides:       network
# Required-Start: ndas
# Should-Start:
# Required-Stop:
# Should-Stop:
# Default-Start:  3 4 5
# Default-Stop:
# Short-Description: KaNDAS daemon
# Description: Monitor the NDAS driver with the KaNDASd daemon
### END INIT INFO

. /etc/rc.status
rc_reset

case "$1" in
    start)
        echo -n "Starting KaNDASd daemon"
        KANDASD_START=1
        KANDASD_STOP=0
        ;;
    restart)
        echo -n "Restarting KaNDASd daemon"
        KANDASD_START=1
        KANDASD_STOP=1
        ;;
    stop)
        echo -n "Stopping KaNDASd daemon"
        KANDASD_START=0
        KANDASD_STOP=1
        ;;
    *)
        err_mesg "Unknown option $1"
        err_mesg "Options {[re]start,stop}"
        my_rc_failed
esac

if test "$KANDASD_STOP" == "1"; then
    pkill -f "kandasd --source"
fi
if test "$KANDASD_START" == "1"; then
    `which kandasd` --detach || rc_failed
fi
rc_status -v
rc_exit
